package ren.kane.asdppp.transaction.cost;

import ren.kane.asdppp.Employee;
import ren.kane.asdppp.PayrollDatabase;
import ren.kane.asdppp.transaction.Transaction;
import ren.kane.asdppp.affiliation.Affiliation;
import ren.kane.asdppp.affiliation.UnionAffiliation;

import java.time.LocalDate;

/**
 * @author renrk(1275) on 2019-04-18 8:41 PM
 **/
public class ServiceChargeTransaction implements Transaction {

    private LocalDate date;

    private int memberId;

    private double charge;

    public ServiceChargeTransaction() {
    }

    public ServiceChargeTransaction(LocalDate date, int memberId, double charge) {
        this.date = date;
        this.memberId = memberId;
        this.charge = charge;
    }

    @Override
    public void execute() {
        Employee employee = PayrollDatabase.getUnionMember(memberId);
        if (null != employee) {
            Affiliation affiliation = employee.getAffiliation();
            if (null != affiliation) {
                UnionAffiliation unionAffiliation = (UnionAffiliation) affiliation;
                unionAffiliation.addServiceCharge(date, charge);
            }
        }
    }
}
